﻿using Pay.Core;
using Pay.DTO;
using Pay.IService;
using Pay.TO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Pay.Web.Areas.Admin.Controllers
{
    [RouteArea("admin")]
    [RoutePrefix("productActivity")]
    public class ProductActivityController : AdminController
    {
        private IProductActivityService _iProductActivityService;
        private IProductService _iProductService;
        private IMerchantService _iMerchantService;
        private IActivityService _iActivityService;

        public ProductActivityController(IProductActivityService iProductActivityService, IProductService iProductService, IMerchantService iMerchantService,
                                        IActivityService iActivityService)
        {
            _iProductActivityService = iProductActivityService;
            _iProductService = iProductService;
            _iMerchantService = iMerchantService;
            _iActivityService = iActivityService;
        }
        [HttpGet]
        public JsonResult GetProducts(GoodsQuery query) {
            query.sale_status = 2;
            query.sell_out = false;
            var tokenMerchant = _iMerchantService.Get(t_RequestMethod.merchant_no);
            query.merchant_id = tokenMerchant.id;
            query.IsTokenMall = true;
            var model = _iProductService.Get(query);
            return Json(ResultToJson.Json(model), JsonRequestBehavior.AllowGet);
        }
        #region 限时购
        public JsonResult GetProductTimeBuyEdit(long activityId) {
            var result = _iProductActivityService.GetProductTimeBuyEdit(activityId);
            return Json(ResultToJson.Json(new product_activity_time_buy_edit(){ list = result, activity = _iActivityService.GetActivity(activityId) }), JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        [ValidateInput(false)]
        public JsonResult SaveProductTimeBuy(product_activity_time_buy_edit dto) {
            var result = _iProductActivityService.AddOrUpdateProductTimeBuy(dto);
            return Json(ResultToJson.Json(result ? " 保存成功" : "未做任何修改", result), JsonRequestBehavior.AllowGet);
        }
        #endregion


    }
}